package com.myBatisTest.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.myBatisTest.entity.Employee;
import com.myBatisTest.mapper.DmployeeMapper;
import com.myBatisTest.service.DmployeeService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;

@Service
public class DmployeeServiceImpl extends ServiceImpl<DmployeeMapper, Employee> implements DmployeeService {

    @Transactional
    @Override
    public boolean save(Employee entity) {
        super.save(entity);
        return true;
    }

    @Cacheable(cacheNames = "my", key = "'DmployeeServiceImpl.getById.'+#id")
    @Override
    public Employee getById(Serializable id) {
        System.out.println("1123123123124124124124124124124");
        return super.getById(id);
    }

    @CacheEvict(cacheNames = "my", key = "'DmployeeServiceImpl.getById.'+#id")
    @Override
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

    @CachePut(cacheNames = "my", key = "'DmployeeServiceImpl.getById.'+#employee.id")
    @Override
    public Employee saveOrUpdateWithCache(Employee employee) {
        super.saveOrUpdate(employee);
        return employee;
    }

    @CachePut(cacheNames = "my", key = "'DmployeeServiceImpl.getById.'+#employee.id")
    @Override
    public Employee saveWithCache(Employee employee) {
        super.save(employee);
        return employee;
    }
}